#include "../bulk_storage/bulk_storage.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


#include "read_connect.h"

int main(int argc, char* argv[]){
  int i;
  char line[83];
  struct connect* conn;
  struct store* conn_store;

  conn_store = store_open_cached("conn_store", "conn_store.fat",
				 sizeof(struct connect), 32, 100);

  i = store_new(conn_store);
  store_read(conn_store, i);
  store_release(conn_store, i);

  while(fgets(line, 82, stdin) != 0){
    if(strcspn(line, " \t\r\n") > 0){
      char* tok;
      char* type;
      i = store_new(conn_store);
      conn = (struct connect*)(store_read(conn_store, i));
      
      conn->sourceatom = (short)(atoi(strtok(line, "\t")));
/*        printf("%d\t", conn->sourceatom); */
    
      conn->sinkatom = (short)(atoi(strtok(NULL, "\t"))); 
/*        printf("%d\t", conn->sinkatom); */
    
      tok = strtok(NULL, "\t");
      type = strstr(tok, "H");
      if(type != 0){conn->bondtype = HBONDED;}
      type = strstr(tok, "C");
      if(type != 0){conn->bondtype = COVALENT;}
      type = strstr(tok, "S");
      if(type != 0){conn->bondtype = SBRIDGED;}
/*        printf("%d\n", conn->bondtype); */
    
      store_write(conn_store, i);
      store_release(conn_store, i);
    }
  }
  
  store_close(conn_store);
  return(0);

}
